using System;
using ProtoModels;
using UnityEngine;

[Serializable]
public class GGStoryAchivementBase
{
	public class GameFinishedParams
	{
		public MatchParameters.MatchParams initParameters;

		public bool isPlayerWinner;

		public int coinsWon;
	}

	public string name;

	public string description;

	public string androidId;

	public string iosId;

	public int index;

	protected AchivementDAO model;

	protected GGStoryAchivementsController achivementController;

	public string achivementId
	{
		get
		{
			return androidId;
		}
	}

	public float progress
	{
		get
		{
			if (isFinished())
			{
				return 1f;
			}
			return Mathf.Clamp01((float)model.numStepsCompleted / (float)Mathf.Max(stepsRequired(), 1));
		}
	}

	public virtual string GetDescription()
	{
		return description;
	}

	public void Init(GGStoryAchivementsController achivementController, AchivementDAO model, int index)
	{
		this.achivementController = achivementController;
		this.model = model;
		this.index = index;
	}

	public virtual void ReportSetupFinished()
	{
	}

	public virtual int stepsRequired()
	{
		return 1;
	}

	public void Save()
	{
		achivementController.Save();
	}

	public int stepsToReport()
	{
		return Mathf.Max(0, model.numStepsCompleted - model.numStepsReported);
	}

	public int stepsToSync()
	{
		return Mathf.Max(0, model.numStepsCompleted - model.numStepsSync);
	}

	public bool isReported()
	{
		return model.numStepsReported > 0;
	}

	public bool isFinished()
	{
		return model.numStepsCompleted >= stepsRequired();
	}

	public bool isSync()
	{
		return stepsToSync() <= 0;
	}

	public virtual void ReportAll()
	{
		model.numStepsReported = stepsRequired();
		Save();
	}

	public void reportSteps(int steps)
	{
		model.numStepsReported += steps;
	}

	public void syncSteps(int steps)
	{
		model.numStepsSync += steps;
	}

	public virtual void ReportGameFinished(GameFinishedParams finishedParams)
	{
		CheckFinished();
	}

	public virtual void CheckFinished()
	{
	}
}
